﻿using Activity.Helper;
using Activity.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Activity.Helper.OAuthHelper;

namespace Activity.API
{
   public class WeixinApi: BaseAPICommand
    {
        public override HttpMethod RequestType
        {
            get
            {
                return HttpMethod.GET; 
            }
        }

        public string OpenID { get; protected set; }
        public override string Url
        {
            get
            {
                //string url = string.Format(WeiXinConst.WeiXin_User_GetInfoUrl, AccessToken.GetAccssTokenFromCacheServer(), this.OpenID);
                //return url;
                return "";
            }
        }

        /// <summary>
        /// 通过code换取网页授权access_token
        /// 这里通过code换取的是一个特殊的网页授权access_token,与基础支持中的access_token
        /// （该access_token用于调用其他接口）不同。公众号可通过下述接口来获取网页授权access_token。
        /// 如果网页授权的作用域为snsapi_base，则本步骤中获取到网页授权access_token的同时，
        /// 也获取到了openid，snsapi_base式的网页授权流程即到此为止。
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static Oauth2AccessToken GetOpenID(string code = "")
        {
            var result = WeiXinHelper.GetOauth2AccessToken(code);
            Log.WriteLog($"通过Code:{code},获取openID{result.openid}");
            return result;
        }
    }
}
